package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.UploadPhoto;
import com.stylefeng.guns.modular.system.service.IUploadPhotoService;

/**
 * 上传信息控制器
 *
 * @author fengshuonan
 * @Date 2018-09-26 16:16:21
 */
@Controller
@RequestMapping("/uploadPhoto")
public class UploadPhotoController extends BaseController {

    private String PREFIX = "/system/uploadPhoto/";

    @Autowired
    private IUploadPhotoService uploadPhotoService;

    /**
     * 跳转到上传信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "uploadPhoto.html";
    }

    /**
     * 跳转到添加上传信息
     */
    @RequestMapping("/uploadPhoto_add")
    public String uploadPhotoAdd() {
        return PREFIX + "uploadPhoto_add.html";
    }

    /**
     * 跳转到修改上传信息
     */
    @RequestMapping("/uploadPhoto_update/{uploadPhotoId}")
    public String uploadPhotoUpdate(@PathVariable Integer uploadPhotoId, Model model) {
        UploadPhoto uploadPhoto = uploadPhotoService.selectById(uploadPhotoId);
        model.addAttribute("item",uploadPhoto);
        LogObjectHolder.me().set(uploadPhoto);
        return PREFIX + "uploadPhoto_edit.html";
    }

    /**
     * 获取上传信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return uploadPhotoService.selectList(null);
    }

    /**
     * 新增上传信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(UploadPhoto uploadPhoto) {
        uploadPhotoService.insert(uploadPhoto);
        return SUCCESS_TIP;
    }

    /**
     * 删除上传信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer uploadPhotoId) {
        uploadPhotoService.deleteById(uploadPhotoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改上传信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(UploadPhoto uploadPhoto) {
        uploadPhotoService.updateById(uploadPhoto);
        return SUCCESS_TIP;
    }

    /**
     * 上传信息详情
     */
    @RequestMapping(value = "/detail/{uploadPhotoId}")
    @ResponseBody
    public Object detail(@PathVariable("uploadPhotoId") Integer uploadPhotoId) {
        return uploadPhotoService.selectById(uploadPhotoId);
    }
}
